﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using System.Net.Mail;
//using System.Web.Mail;

namespace Nivdal
{
    public partial class Advertise : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = Resources.Resource.Default_PageTitle + ", " + Resources.Resource.Advertise_PageTitle;            

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            lblMessage.Text = "";
            string MailSender = "nivdal@gmail.com";
            if (EmailTextBox.Text.Length > 8)
                MailSender = EmailTextBox.Text.Trim();
            if (contactTextArea.Text.Length < 10) //Check if there are 10 chars of charcter minimum
                lblMessage.Text = Resources.Resource.Advertise_MissingContent;
            else
            {
                try
                {
                    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                    message.Subject = ContactSubjectTextBox.Text.Trim();
                    message.Sender = new System.Net.Mail.MailAddress(MailSender);
                    message.To.Add("nivdal@gmail.com");
                    message.Body = Environment.NewLine + contactTextArea.Text.Trim();
                    message.BodyEncoding = System.Text.Encoding.UTF8;
                    //System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("127.0.0.1");
                    SmtpClient smtp = new SmtpClient();
                    // gmail only - remove when local
                    // smtp.EnableSsl = true;
                    smtp.Send(message);
                    Response.Redirect("GeneralMessage.aspx?MessageString=azx4qaMM1qvPOTHJA");

                    //MailAddress SendFrom = new MailAddress(MailSender);
                    //MailAddress SendTo = new MailAddress("nivdal@gmail.com");
                    //MailMessage MultyMessage = new MailMessage(SendFrom, SendTo);
                    ///MultyMessage.Subject = ContactSubjectTextBox.Text.Trim();
                    ///MultyMessage.Body = " ";
                    ///MultyMessage.Body += Environment.NewLine + contactTextArea.Text.Trim();
                    ///MultyMessage.BodyEncoding = System.Text.Encoding.UTF8;
                    ///SmtpClient emailClient = new SmtpClient("127.0.0.1");
                    ///emailClient.Send(MultyMessage);
                    ///Response.Redirect("GeneralMessage.aspx?MessageString=azx4qaMM1qvPOTHJA");


                }
                catch (Exception exc)
                {
                    lblMessage.Text = ("Send failure: " + exc.ToString());
                }


            }
        }

        protected override void InitializeCulture()
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string UserUICulture = GND.GetUserUICulture();
            string UserCulture = GND.GetUserCulture();
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(UserUICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(UserCulture);
        }
    }
}